/**
 * Copyright: Copyright (c)2011
 * Company: 易宝支付(YeePay)
 */
package net.loyintean.pearlshell.base;

import java.util.ConcurrentModificationException;

/**
 * @author：jun.lin@yeepay.com
 * @since：2015年2月9日 下午11:07:49
 * @version:
 */
public class ThreadLocalTester implements Runnable {

	private static final ThreadLocal<Integer> local = new ThreadLocal<Integer>();

	private int num;

	public ThreadLocalTester(int n) {
		super();
		this.num = n;
	}

	/**
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public void run() {
		local.set(num);

		System.out.println(local.get() + "====" + num);

		if (local.get() != num) {
			throw new ConcurrentModificationException();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		for (int i = 0; i < 100; i++) {
			Thread t = new Thread(new ThreadLocalTester(i));
			t.start();
		}
	}

}
